#!/bin/bash

# VOID LINUX POST INSTALL DIALOG

# -----------------------------------------------------------------------------
# 0. settings
# 1. INSTALL DIALOG
# 2. SYSTEM UPDATE
# 3. INSTALL BASE SYSTEM
#     -> CORE
#     -> NETWORK
#     -> VIDEO
#     -> AUDIO
#     -> XORG
# 4. INSTALL PKGS
# 5. INSTALL DEVELOPMENT PKGS
# 6. INSTALL GRAPHICS PKGS
# 7. INSTALL PRINTERS & SCANNERS PKGS
# 8. INSTALL BLUETOOTH PKGS
# 9. INSTALL VIRTUAL MANAGER
# 10. COPY CONFIG
# 11. FINAL

# -----------------------------------------------------------------------------
# --- SETTINGS
# -----------------------------------------------------------------------------
config_directory="$HOME/.config"

green='\033[0;32m'
magenta='\x1b[38;5;206m'
normal='\033[0m'
bold='\033[1m'
no_color='\033[0m'
date=$(date +%s)

# -----------------------------------------------------------------------------
# --- INSTALL DIALOG
# -----------------------------------------------------------------------------
sudo xbps-install -Sy dialog # Tool to display dialog boxes from shell scripts

# -----------------------------------------------------------------------------
# --- 1. SYSTEM UPDATE
# -----------------------------------------------------------------------------
system_update(){
    echo -e "${green}${bold}[*] DOING A SYSTEM UPDATE, CAUSE STUFF MAY BREAK IF IT'S NOT THE LATEST VERSION ...${normal}${no_color}"
    echo
    sleep 1

    sudo xbps-install -Suy
    sudo xbps-install -Sy void-repo-nonfree
    sudo xbps-install -Sy void-repo-multilib
    sudo xbps-install -Sy void-repo-multilib-nonfree
    vkpurge rm all # Delete old cores

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 2. INSTALL BASE SYSTEM
# -----------------------------------------------------------------------------
install_base_system(){
    echo -e "${green}${bold}[*] INSTALLING BASE SYSTEM ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        # CORE ----------------------------------------------------------------
        'base-devel'               # Void Linux development tools meta package
        'linux-firmware-intel'     # Binary firmware blobs for the Linux kernel - Intel CPU/GPU microcode
        'dbus'                     # Message bus system
        'dbus-elogind'             # Message bus system (transitional dummy package)
        'elogind'                  # Standalone logind fork
        'polkit'                   # Authorization Toolkit
        # 'seatd'                  # Minimal seat management daemon
        'acpi'                     # Informations about ACPI devices (battery, thermal sensors and power)

        # NETWORK -------------------------------------------------------------
        'NetworkManager'           # Network Management daemon
        'NetworkManager-openvpn'   # NetworkManager VPN plugin for OpenVPN
        'NetworkManager-vpnc'      # NetworkManager VPN plugin for VPNC
        'network-manager-applet'   # NetworkManager panel applet for GNOME
        'wpa_supplicant'           # WPA/WPA2/IEEE 802.1X Supplicant
        'openvpn'                  # Easy-to-use, robust, and highly configurable VPN
        'dhcpcd'                   # RFC2131 compliant DHCP client
        'dhclient'                 # Client from the Internet Software Consortium's implementation of DHCP
        'libsecret'                # GObject based library for accessing the Secret Service API

        # VIDEO ---------------------------------------------------------------
        'mesa'                     # Open source implementation of OpenGL and Vulkan
        'mesa-dri'                 # Mesa DRI drivers
        'mesa-intel-dri'           # Mesa DRI drivers for Intel GPUs (transitional dummy package)
        'mesa-vulkan-intel'        # Mesa Intel Vulkan driver
        'xf86-video-intel'         # Xorg DDX Intel video driver
        'intel-video-accel'        # Intel Video Acceleration meta-pkg
        'nvidia'                   # NVIDIA drivers for linux - Libraries and Utilities

        # AUDIO ---------------------------------------------------------------
        'pulseaudio'               # Featureful, general-purpose sound server
        'alsa-utils'               # Advanced Linux Sound Architecture (ALSA) utilities
        'alsa-plugins-pulseaudio'  # Advanced Linux Sound Architecture (ALSA) extra plugins - Pulseaudio output plugin
        'pipewire'                 # Server and user space API to deal with multimedia pipelines
        'alsa-pipewire'            # Server and user space API to deal with multimedia pipelines - ALSA client library
        'apulse'                   # PulseAudio emulation for ALSA
        'AlsaMixer.app'            # Simple dockable mixer application for Linux with ALSA drivers

        # XORG ----------------------------------------------------------------
        'xorg'                    # X.org meta-package
        'xorg-server'             # X11 server from X.org
        'xorg-apps'               # X.org applications
        'libX11'                  # Base X libraries from Xorg
        'libX11-devel'            # Base X libraries from Xorg - development files
        'libXft-devel'            # Library for configuring and customizing font access - development files
        'libXinerama-devel'       # X PanoramiX extension library - development files
        'freetype-devel'          # Font rendering engine and library API - development files
        'fontconfig-devel'        # Library for configuring and customizing font access - development files
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 3. INSTALL PKGS
# -----------------------------------------------------------------------------
install_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING PKGS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        # TERMINALS -----------------------------------------------------------
        'alacritty'               # Cross-platform, GPU-accelerated terminal emulator
        'kitty'                   # Modern, hackable, featureful, OpenGL based terminal emulator

        # INTERNET ------------------------------------------------------------
        'firefox'                 # Mozilla Firefox web browser
        'qbittorrent'             # Free software alternative to µtorrent

        # PKGS ----------------------------------------------------------------
        'neovim'                  # Library for configuring and customizing font access - development files
        'wget'                    # GNU wget download utility
        'curl'                    # Client that groks URLs
        'gnupg'                   # GNU Privacy Guard (2.x)
        'numlockx'                # Activate NumLock at startup
        'chrony'                  # Versatile implementation of the Network Time Protocol (NTP) Служба времени
        # 'fbxkb'                 # Lightweight X keyboard layout indicator, uses GTK+2
        'gxkb'                    # Lightweight GTK+3 X11 keyboard layout indicator and switcher
        'psutils'                 # Set of utilities to manipulate PostScript files
        'gufw'                    # GTK+ frontend for ufw
        'hardinfo'                # System information and benchmark tool
        'inxi'                    # Full featured system information script
        'jq'                      # Command-line JSON processor
        'ntp'                     # Network Time Protocol daemon and utilities
        'numlockx'                # Activate NumLock at startup
        'openssh'                 # OpenSSH free Secure Shell (SSH) client and server implementation
        'rsync'                   # Remote fast incremental file transfer tool
        'tlp'                     # Advanced power management tool for Linux
        'git'                     # Git Tree History Storage Tool
        'htop'                    # Interactive process viewer
        'neofetch'                # Simple system information script
        # 'pfetch'                # System information tool written in POSIX sh
        'dunst'                   # Lightweight and customizable notification daemon
        'fish-shell'              # User friendly shell intended mostly for interactive use
        'man-db'                  # On-line manual database
        'ripgrep'                 # Fast search tool inspired by ag and grep
        'fzf'                     # Command-line fuzzy finder
        'picom'                   # Lightweight compositor for X11 (previously a compton fork)
        'yt-dlp'                  # CLI program to download videos from YouTube and other sites
        'cmatrix'                 # Simulates the display from The Matrix
        'ncdu'                    # NCurses Disk Usage utility
        'calcurse'                # Text-based calendar and scheduling application
        'unclutter'               # A small program for hiding the mouse cursor
        'bat'                     # Cat(1) clone with syntax highlighting and Git integration
        'exa'                     # Modern replacement for ls
        'dosfstools'              # DOS filesystem tools
        'brightnessctl'           # Read and control device brightness
        'lazygit'                 # Simple terminal UI for git commands
        'cava'                    # Console-based Audio Visualizer for ALSA
        'ueberzug'                # Command line util which allows drawing images on terminals
        'volctl'                  # Lightweight volume control for pulseaudio in your systray
        'caffeine-ng'             # Temporarily inhibits the screensaver and sleep mode
        'feh'                     # Fast and light imlib2-based image viewer
        'xclip'                   # Command line interface to the X11 clipboard

        # ARHIVATORS ----------------------------------------------------------
        'unrar'                   # Unarchiver for .rar files (non-free version)
        'unzip'                   # List, test and extract compressed files in a ZIP archive
        'zip'                     # Create/update ZIP files compatible with pkzip
        'p7zip'                   # Command-line version of the 7zip compressed file archive (transitional dummy package)
        'file-roller'             # GNOME Front-end to archiving programs like tar and zip

        # FILEMANAGER ---------------------------------------------------------
        'ranger'                  # File manager with an ncurses frontend written in Python
        'mc'                      # User-friendly file manager and visual shell
        'nemo'                    # Cinnamon file manager (nautilus fork)
        'tumbler'                 # D-Bus Thumbnailer service

        # PASSWORDS -----------------------------------------------------------
        'pass'                    # Stores, retrieves, generates, and synchronizes passwords securely
        'zulucrypt-gui'           # Frontend to cryptsetup and Veracrypt for harddrive and file encryption - GUI tools
        'keepassxc'               # KeePassXC is a cross-platform port of “Keepass Password Safe”
        'catfish'                 # Versatile file search

        # MEDIA ---------------------------------------------------------------
        'mpd'                     # Flexible, powerful, server-side application for playing music
        'ncmpcpp'                 # Ncurses mpd client inspired by ncmpc
        'mpv'                     # Video player based on MPlayer/mplayer2
        'cmus'                    # Small, fast and powerful console music player
        'ffmpeg'                  # Decoding, encoding and streaming software

        # PRODUCTIVITY --------------------------------------------------------
        'galculator'              # GTK+ based scientific calculator (GTK+3)
        'zathura'                 # Highly customizable and functional document viewer
        'zathura-pdf-mupdf'       # PDF support for zathura (using mupdf)
        'flameshot'               # Powerful yet simple to use screenshot software for GNU/Linux
        'sxiv'                    # Neo (or New or Not) Simple (or Small or Suckless) X Image Viewer - (transitional package)
        'imagemagick'             # Create, edit, compose, or convert bitmap images
        'pngcrush'                # Tool for optimizing the compression of PNG files

        # USER FOLDERS --------------------------------------------------------
        'autofs'                  # Kernel-based automounter for Linux
        'exfat-utils'             # Utilities for exFAT file system
        # 'gparted'               # Gnome Partition Editor
        'ntfs-3g'                 # Stable Read/Write NTFS Driver in userspace
        'parted'                  # GNU Parted disk partition resizing program
        'gvfs'                    # Userspace virtual filesystem
        'gvfs-mtp'                # Userspace virtual filesystem - MTP backend
        'gvfs-afc'                # Userspace virtual filesystem - Apple mobile device backend
        'gvfs-gphoto2'            # Userspace virtual filesystem - gphoto2 (PTP camera/MTP media player) backend
        'gvfs-smb'                # Userspace virtual filesystem - SMB/CIFS (Windows client) backend
        'udiskie'                 # Removable disk automounter using udisks
        'udisks2'                 # Disk Management Service, version 2
        'xdg-utils'               # Tools to assist applications with various desktop integration tasks
        'xdg-user-dirs-gtk'       # GTK+ tool to help manage user directories
        'xdg-user-dirs'           # Tool to help manage user directories

        # THEME ---------------------------------------------------------------
        'arc-theme'               # Flat theme with transparent elements for GTK and GNOME Shell
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 4. INSTALL DEVELOPMENT PKGS
# -----------------------------------------------------------------------------
install_development_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING DEVELOPMENT PKGS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        # TERMINALS -----------------------------------------------------------
        'nodejs'                  # Evented I/O for V8 javascript
        'yarn'                    # Fast, reliable, and secure dependency management
        'filezilla'               # Fast and reliable FTP, FTPS and SFTP client
        'vscode'                  # Microsoft Code for Linux
        'tmux'                    # Terminal Multiplexer
        'dbeaver'                 # Free Universal Database Tool
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    sleep 1

    # INSTALL ASTRONVIM -------------------------------------------------------
    mv ~/.config/nvim ~/.config/nvim.bak
    mv ~/.local/share/nvim ~/.local/share/nvim.bak
    mv ~/.local/state/nvim ~/.local/state/nvim.bak
    mv ~/.cache/nvim ~/.cache/nvim.bak
    git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim

    # ASTRONVIM USER SETTINGS -------------------------------------------------
    git clone https://notabug.org/tpp17/astro_nvim_user_v3.git $HOME/.config/nvim/lua/user

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 5. INSTALL GRAPHICS PKGS
# -----------------------------------------------------------------------------
install_graphics_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING GRAPHICS PKGS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        'gcolor3'                 # Color selection dialog written in GTK+3
        'gimp'                    # GNU image manipulation program
        'inkscape'                # Vector-based drawing program
        'krita'                   # Painting and image editing program
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 6. INSTALL PRINTERS & SCANNERS PKGS
# -----------------------------------------------------------------------------
install_printers_and_scanners_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING PRINTERS & SCANNERS PKGS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        'cups'                      # Common Unix Printing System
        'cups-filters'              # OpenPrinting CUPS Filters
        'cups-pdf'                  # PDF printer for cups
        'ghostscript'               # Interpreter for the PostScript language
        'gsfonts'                   # URW+ base35 fonts
        'system-config-printer'     # CUPS printer configuration tool and status applet
        'skanlite'                  # Image Scanning Application
        'simple-scan'               # GTK Simple scanning utility
        'sane'                      # Scanner Access Now Easy
        'sane-airscan'              # SANE universal driver for eSCL (Apple AirScan) and WSD
        'gutenprint'                # Top quality printer drivers for POSIX systems
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 7. INSTALL BLUETOOTH PKGS
# -----------------------------------------------------------------------------
install_bluetooth_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING BLUETOOTH PKGS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        'bluez'                     # Bluetooth tools and daemons
        'bluez-alsa'                # Bluetooth Audio ALSA Backend
        'blueman'                   # GTK+ Bluetooth Manager
        # 'blueberry'
        # 'bluez-utils'
        # 'bluez-firmware'
        # 'pulseaudio-bluetooth'
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 8. INSTALL VIRTUAL MANAGER
# -----------------------------------------------------------------------------
install_virtual_manager_pkgs(){
    echo -e "${green}${bold}[*] INSTALLING QEMU A GENERIC AND OPEN SOURCE MACHINE EMULATOR AND VIRTUALIZER ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        'virt-manager'              # User interface for managing virtual machines
        'qemu'                      # Open Source Processor Emulator
        'bridge-utils'              # Layer2 ethernet bridging for Linux
        # 'ebtables'                  # Filtering tool for a Linux-based bridging firewall (32bit)
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 9. INSTALL FONTS
# -----------------------------------------------------------------------------
install_fonts(){
    echo -e "${green}${bold}[*] INSTALLING FONTS ...${normal}${no_color}"
    echo
    sleep 1

    PKGS=(
        'nerd-fonts'              # Iconic font aggregator, collection and patcher
        'noto-fonts-ttf'          # Google Noto TTF Fonts
        'noto-fonts-emoji'        # Google Noto Emoji Fonts
        'noto-fonts-cjk'          # Google Noto CJK Fonts
        'font-awesome'            # An iconic font
        'font-hack-ttf'           # A typeface designed for source code
        'terminus-font'           # Clean, fixed width bitmap font
        'font-iosevka'            # Slender monospace sans-serif and slab-serif typeface
    )

    for PKG in "${PKGS[@]}"; do
        echo -e "${green}${bold}[*] START "$PKG" ---${normal}${no_color}"
        sudo xbps-install -Sy "$PKG"
        echo -e "${magenta}${bold}[+] DONE "$PKG" ---${normal}${no_color}"
        echo
        sleep 1
    done

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 10. COPY CONFIG
# -----------------------------------------------------------------------------
copy_config(){
    echo -e "${green}${bold}[*] COPY CONFIG ...${normal}${no_color}"
    echo
    sleep 1

    xdg-user-dirs-update

    sleep 1

    [ -d "$config_directory"/alacritty ] && mv "$config_directory"/alacritty "$config_directory"/alacritty_$date && echo "alacritty configs detected, backing up."
    [ -d "$config_directory"/kitty ] && mv "$config_directory"/kitty "$config_directory"/kitty_$date && echo "alacritty configs detected, backing up."
    [ -d "$config_directory"/dunst ] && mv "$config_directory"/dunst "$config_directory"/dunst_$date && echo "dunst configs detected, backing up."
    [ -d "$config_directory"/mpd ] && mv "$config_directory"/mpd "$config_directory"/mpd_$date && echo "mpd configs detected, backing up."
    [ -d "$config_directory"/ncmpcpp ] && mv "$config_directory"/ncmpcpp "$config_directory"/ncmpcpp_$date && echo "ncmpcpp configs detected, backing up."
    [ -d "$config_directory"/ranger ] && mv "$config_directory"/ranger "$config_directory"/ranger_$date && echo "ranger configs detected, backing up."
    [ -d "$config_directory"/zathura ] && mv "$config_directory"/zathura "$config_directory"/zathura_$date && echo "zathura configs detected, backing up."
    [ -d "$config_directory"/picom ] && mv "$config_directory"/picom "$config_directory"/picom_$date && echo "picom configs detected, backing up."

    # [ -e "$config_directory"/Code\ -\ OSS/User/settings.json ] && mv "$config_directory"/Code\ -\ OSS/User/settings.json "$config_directory"/Code\ -\ OSS/User/settings.json_$date && echo "Vsc configs detected, backing up."

    sleep 1

    cp -r $HOME/.dotfiles/config/* "$config_directory"

    # Symlinks Config
    ln -s $HOME/.dotfiles/other_config/alias ~/.alias
    ln -s $HOME/.dotfiles/other_config/tmux.conf ~/.tmux.conf
    ln -s $HOME/.dotfiles/other_config/xinitrc ~/.xinitrc
    ln -s $HOME/.dotfiles/other_config/Xresources ~/.Xresources

    cp -r $HOME/.dotfiles/other_config/gtkrc-2.0 ~/.gtkrc-2.0
    cp -r $HOME/.dotfiles/config/gtk-2.0 ~/.config
    cp -r $HOME/.dotfiles/config/gtk-3.0 ~/.config

    rm $HOME/.config/alacritty/alacritty.yml
    ln -s $HOME/.dotfiles/config/alacritty/alacritty.yml $HOME/.config/alacritty/alacritty.yml
    rm $HOME/.config/cava/config
    ln -s $HOME/.dotfiles/config/cava/config $HOME/.config/cava/config
    rm $HOME/.config/dunst/dunstrc
    ln -s $HOME/.dotfiles/config/dunst/dunstrc $HOME/.config/dunst/dunstrc
    rm $HOME/.config/kitty/kitty.conf
    ln -s $HOME/.dotfiles/config/kitty/kitty.conf $HOME/.config/kitty/kitty.conf
    rm $HOME/.config/mpd/mpd.conf
    ln -s $HOME/.dotfiles/config/mpd/mpd.conf $HOME/.config/mpd/mpd.conf
    rm $HOME/.config/mpv/mpv.conf
    ln -s $HOME/.dotfiles/config/mpv/mpv.conf $HOME/.config/mpv/mpv.conf
    rm $HOME/.config/ncmpcpp/config
    ln -s $HOME/.dotfiles/config/ncmpcpp/config $HOME/.config/ncmpcpp/config
    rm $HOME/.config/ranger/rc.conf
    ln -s $HOME/.dotfiles/config/ranger/rc.conf $HOME/.config/ranger/rc.conf
    rm $HOME/.config/zathura/zathurarc
    ln -s $HOME/.dotfiles/config/zathura/zathurarc $HOME/.config/zathura/zathurarc
    rm $HOME/.config/picom/picom.conf
    ln -s $HOME/.dotfiles/config/picom/picom.conf $HOME/.config/picom/picom.conf
    rm $HOME/".config/Code - OSS/User/settings.json"
    ln -s $HOME/.dotfiles/config/vscode/settings.json $HOME/".config/Code - OSS/User/settings.json"

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 11. SERVICES & GROUPS
# -----------------------------------------------------------------------------
services_and_groups(){
    echo -e "${green}${bold}[*] START SERVICES & GROUPS  ...${normal}${no_color}"
    echo
    sleep 1

    # ADD SERVICES ------------------------------------------------------------
    sudo ln -s /etc/sv/bluetoothd/ /var/service/
    sudo ln -s /etc/sv/NetworkManager/ /var/service/
    sudo ln -s /etc/sv/cupsd/ /var/service/
    sudo ln -s /etc/sv/dbus /var/service/
	sudo ln -s /etc/sv/elogind /var/service/
	sudo ln -s /etc/sv/polkitd /var/service/
	sudo ln -s /etc/sv/ntpd /var/service/
	sudo ln -s /etc/sv/alsa /var/service/

    sleep 1

    # ADD GROUPS --------------------------------------------------------------
    sudo usermod -aG bluetooth $USER
    sudo usermod -aG audio $USER
    sudo usermod -aG network $USER
    sudo usermod -a -G input $USER
	sudo usermod -a -G audio $USER
	sudo usermod -a -G video $USER
	sudo usermod -a -G rfkill $USER
	sudo usermod -a -G power $USER
	sudo usermod -a -G bluetooth $USER
	sudo usermod -a -G pulse-access $USER
	sudo usermod -aG libvirt $USER
	sudo usermod -aG kvm $USER
	sudo usermod -aG socklog $USER

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}
# -----------------------------------------------------------------------------
# --- 12. FINAL
# -----------------------------------------------------------------------------
final(){
    echo -e "${green}${bold}[*] COPY CONFIG ...${normal}${no_color}"
    echo
    sleep 1

    # ADD WALLPAPERS ----------------------------------------------------------
    cp -r $HOME/.dotfiles/wallpaper $HOME/Pictures/Wallpapers

    # ADD ALIASES -------------------------------------------------------------
    echo "[ -f ~/.alias ] && source ~/.alias" >> $HOME/.bashrc

    sleep 1

    # RANGER DEV ICONS --------------------------------------------------------
    git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons

    # UPDATE FONTS CACHE ------------------------------------------------------
    fc-cache -fv

    echo
    echo -e "${magenta}${bold}[+] DONE ----------------------------------------${normal}${no_color}"
    echo
}

# -----------------------------------------------------------------------------
# --- 13. REBOOT
# -----------------------------------------------------------------------------
reboot(){
    sudo reboot
}

# -----------------------------------------------------------------------------
# --- DIALOG SETTINGS
# -----------------------------------------------------------------------------
cmd=(dialog --clear --separate-output --checklist "Select (with space) what script should do.\\nChecked options are required for proper installation, do not uncheck them if you do not know what you are doing." 26 86 16)
options=(
    1 "SYSTEM UPDATE" off
    2 "INSTALL BASE SYSTEM (CORE, NETWORK, VIDEO, AUDIO, XORG)" off
    3 "INSTALL PKGS" off
    4 "INSTALL DEVELOPMENT PKGS" off
    5 "INSTALL GRAPHICS PKGS" off
    6 "INSTALL PRINTERS & SCANNERS PKGS" off
    7 "INSTALL BLUETOOTH PKGS" off
    8 "INSTALL VIRTUAL MANAGER PKGS" off
    9 "INSTALL FONTS" off
    10 "COPY CONFIG" off
    11 "SERVICES & GROUPS" off
    12 "FINAL" off
    13 "REBOOT" on
)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)

clear

for choice in $choices
do
    case $choice in
        1) system_update ;;
        2) install_base_system ;;
        3) install_pkgs ;;
        4) install_development_pkgs ;;
        5) install_graphics_pkgs ;;
        6) install_printers_and_scanners_pkgs ;;
        7) install_bluetooth_pkgs ;;
        8) install_virtual_manager_pkgs ;;
        9) install_fonts ;;
        10) copy_config ;;
        11) services_and_groups ;;
        12) final ;;
        13) reboot ;;
    esac
done

# -----------------------------------------------------------------------------
# Video Redactors
# 'kdenlive'                # Non-linear video editor
